<template>
  <div class="app-container" style="min-height: auto">
    <!-- 表格-条件筛区域  -->
<!--    <div class="filter-container">-->
<!--      <el-input placeholder="请输入关键字" v-model="searchParam.SEARCH_LIKE_name" style="width: 200px;" class="filter-item" @keyup.enter.native="handleFilter"/>-->
<!--      <el-button class="filter-item" type="primary" icon="el-icon-search" @click="handleFilter"> 搜索 </el-button>-->
<!--      <el-button class="filter-item" style="margin-left: 10px;" type="primary" icon="el-icon-plus" @click="handleCreate"> 新增 </el-button>-->
<!--    </div>-->

    <!-- 表格-内容区域 -->
    <el-table  :key="tableKey" :data="tableList" border fit highlight-current-row style="width: 100%;">
      <el-table-column v-if="num === 1" v-for="column in examColumns" :key="column.prop"
                       :prop="column.prop"
                       :label="column.label"
                       :width="column.width"
                       :align="column.align?column.align:'center'"
                       :min-width="column.minWidth"
                       :sortable="column.sortable"
                       :fixed="column.fixed"
                       :type="column.type" :formatter="column.formatter">
        <template slot-scope="scope">
          <!-- 行内显示图片 -->
          <img v-if="column.imgFlag==true" :src=" scope.row[column.prop].indexOf('http://') >-1 ?  scope.row[column.prop] : ( CMBASE.baseFileContext + scope.row[column.prop] ) " width="60" height="60" class="img"/>
          <!-- 行内显示开关按钮 -->
          <el-switch v-else-if="column.switchFlag==true" v-model="scope.row[column.prop]" :active-value="1" :inactive-value="0"  disabled />
          <!-- 行内显示tag标签 -->
          <span  v-else-if="column.tagFlag==true">
                        <span v-for="item in column.tagFormatter" :key="item.value" >
                            <el-tag v-if="item.value==scope.row[column.prop]"   :type="item.type">{{item.text}}</el-tag>
                        </span>
                    </span>
          <!-- 行内格式自定义 -->
          <span v-else-if="column.formatter"> {{column.formatter(scope.row)}}</span>
          <!--默认显示文本-->
          <span v-else>{{scope.row[column.prop]}}</span>
        </template>
      </el-table-column>

      <el-table-column v-if="num === 2" v-for="column in courseColums" :key="column.prop"
                       :prop="column.prop"
                       :label="column.label"
                       :width="column.width"
                       :align="column.align?column.align:'center'"
                       :min-width="column.minWidth"
                       :sortable="column.sortable"
                       :fixed="column.fixed"
                       :type="column.type" :formatter="column.formatter">
        <template slot-scope="scope">
          <!-- 行内显示图片 -->
          <img v-if="column.imgFlag==true" :src=" scope.row[column.prop].indexOf('http://') >-1 ?  scope.row[column.prop] : ( CMBASE.baseFileContext + scope.row[column.prop] ) " width="60" height="60" class="img"/>
          <!-- 行内显示开关按钮 -->
          <el-switch v-else-if="column.switchFlag==true" v-model="scope.row[column.prop]" :active-value="1" :inactive-value="0"  disabled />
          <!-- 行内显示tag标签 -->
          <span  v-else-if="column.tagFlag==true">
                        <span v-for="item in column.tagFormatter" :key="item.value" >
                            <el-tag v-if="item.value==scope.row[column.prop]"   :type="item.type">{{item.text}}</el-tag>
                        </span>
                    </span>
          <!-- 行内格式自定义 -->
          <span v-else-if="column.formatter"> {{column.formatter(scope.row)}}</span>
          <!--默认显示文本-->
          <span v-else>{{scope.row[column.prop]}}</span>
        </template>
      </el-table-column>
    </el-table>

    <!-- 表格-页脚区域 -->
    <pagination v-show="tableTotal>0" :total="tableTotal" :page.sync="pageRequest.pageNum" :limit.sync="pageRequest.pageSize" @pagination="getList"/>

  </div>
</template>
<script>
import Pagination from '@/components/Pagination' // 分页栏信息
export default {
  name: 'xxxx',
  components: {
    Pagination,
  },
  props:{
    tableList: {
      type:Array,
      default: [],
    },//表格数据源
    num:{
      type:Number,
    },
  },
  directives: {   },
  filters: { },
  data() {
    return {
      tableKey: 0,

      tableTotal: 0,//表格总条数数据
      listLoading: true,
      pageRequest: { pageNum: 1, pageSize: 10, },
      searchParam:{},
      dialogFormVisible: false,//默认不显示弹出框
      operation: true, // true:新增, false:编辑
      editLoading: false,//保存表单时loading框
      examColumns: [
        {prop: 'examName',  label: '考试名称',  sortable:false  },
        {prop: 'memberScore',  label: '考试分数',  sortable:false },
        {prop: 'totalScore',  label: '试卷总分',  sortable:false  },
        {prop: 'passScore',  label: '通过分数',  sortable:false  },
        {prop: 'startTime',  label: '考试时间',  sortable:false  },
        {prop: 'resultStatus',  label: '是否通过',  sortable:false  ,tagFlag:true,
          tagFormatter:[
            { text: '通过', value: 1, type: 'success' },
            { text: '拒绝', value: 2, type: 'success' },
            { text: '待批改', value: 0, type: 'success' },
            { text: '未开考', value: -1, type: 'success' },
          ]
        },
      ],
      courseColums:[
        {prop: 'courseName',  label: '课程名称',  sortable:false  },
        {prop: 'durationTotal',  label: '课程时长',  sortable:false  },
        {prop: 'learnDuration',  label: '学习时长',  sortable:false  },
        {prop: 'learnProcess',  label: '课程进度',  sortable:false , formatter:function (data){ return ((data.learnProcess=null?0:data.learnProcess)).toFixed(0)+"%" } },
      ],
      fileList: [],
      // 新增编辑界面数据
      dataForm: {},
      //表单检验规则
      dataFormRules: {
      },
    }
  },
  created() {

  },
  methods: {
    //获取表格数据
    getList() {
      this.listLoading = true
      //【API请求】----获取表格列表数据
      this.$api.getVExamMemberListList(this.pageRequest).then(response => {
        this.tableList = response.data.content
        this.tableTotal = response.data.total
        this.listLoading = false;
      }).catch((res) => {
        this.$message({  message: '列表获取失败', type: 'error' })
      })
    },
    //表格数据筛选
    handleFilter() {
        this.pageRequest = {
            pageNum: 1,
            pageSize: 10,
        }
      this.pageRequest.searchParam = this.searchParam
      this.getList()
    },
    //【按钮点击】--- 弹出新增表单
    handleCreate() {
      this.operation = true;
      this.initDataForm();
      this.dialogFormVisible = true
      this.$nextTick(() => {
        this.$refs['dataForm'].clearValidate()
        this.editLoading = false;
      })
    },
    //【按钮点击】--- 弹出编辑表单
    handleUpdate(row) {
      this.operation = false;
      this.dataForm = Object.assign({}, row)
      //显示编辑菜单
      this.dialogFormVisible = true
      this.$nextTick(() => {
        this.$refs['dataForm'].clearValidate()
        this.editLoading = false;
      })
    },
    //保存表单数据
    saveFormData() {
      this.$refs['dataForm'].validate((valid) => {
        if (!valid) {
          return false;
        }
        this.editLoading = true;
        //【API请求】----保存数据
        this.$api.saveVExamMemberList(this.dataForm).then(() => {
          this.editLoading = false;//关闭loading框
          this.dialogFormVisible = false;//关闭表单页面
          this.initDataForm();//重置表单数据
          this.getList();//重新获取表格数据
          this.$notify({ title: '成功',  message: '保存成功', type: 'success', duration: 2000 })
        })
      })
    },
    //【按钮点击】---删除行
    handleDelete(row) {
      this.$confirm('确认删除该记录吗？', '提示', {}).then(() => {
        //【API请求】---- 删除数据
        this.$api.deleteVExamMemberList({ids:row.id}).then(() => {
          this.$message({  message: '操作成功', type: 'success' })
            this.pageRequest.pageNum = 1
          this.getList();
        })
      }).catch(() => {
        this.$message({  message: '操作失败', type: 'error' })
      });
    },
    //初始化表单数据，重新渲染
    initDataForm(){
      this.dataForm = {
        practiceFrameTextContentId: '' ,
        frameTextContentId: '' ,
        memberId: '' ,
        leftCount: '' ,
        examType: '' ,
        resultStatus: '' ,
        passScore: '' ,
        examDuration: '' ,
        ifPractice: '' ,
        examStatus: '' ,
        memberScorePractice: '' ,
        totalScore: '' ,
        signCountLimit: '' ,
        signStatus: '' ,
        resultStatusPractice: '' ,
        memberScore: '' ,
        questionCount: '' ,
        examCount: '' ,
        status: '' ,
        certId: '' ,
        username: '' ,
        endTime: '' ,
        id: '' ,
        examLotId: '' ,
        createTime: '' ,
        examName: '' ,
        signEndTime: '' ,
        endTimePractice: '' ,
        remark: '' ,
        examId: '' ,
        startTime: '' ,
        examImg: '' ,
        headPic: '' ,
        signStartTime: '' ,
      };
    },
    //关闭表单弹出框
    closeDialog(){
      this.$refs['dataForm'].resetFields();
      this.dialogFormVisible = false
    },

  }


}
</script>